package com.xjtu.project.controller;
import com.aliyun.oss.AliyunOSSOperator;
import com.xjtu.project.common.utls.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;
    @PostMapping("/api/upload")
    public JsonResponse<String> upload(@RequestParam("file") MultipartFile file) throws Exception {
        //后端接收上传过来的文件，然后通过aliyun oss上传 并且返回一个url
        String url = aliyunOSSOperator.upload(file.getBytes(),file.getOriginalFilename());
        return JsonResponse.success(url);
    }

}
